<template>
  <div>
    <div ref="bar" class="bar" :style="`width:${w}%`"></div>
    <div class="eartical" v-if="contentData">
      <van-nav-bar fixed>
        <template #left>
          <i
            class="iconfont icon-fanhui"
            style="font-size: 20px; font-weight: 600"
            @click="$router.back()"
          ></i>
        </template>
        <template #title>
          <span style="font-size: 18px; font-weight: 600">{{
            contentData.title
          }}</span>
        </template>
        <template #right>
          <i
            class="iconfont icon-fenxiang"
            style="font-size: 22px; font-weight: 600"
          ></i>
        </template>
      </van-nav-bar>
      <img :src="contentData.banner | picUrl" alt="" />
      <div class="content">
        <div class="info">
          <span class="label">{{ contentData.info.label }}</span>
          <span class="time">{{ contentData.info.time }}</span>
          <div class="map">
            <span
              v-for="(item, index) in contentData.info.categroy"
              :key="index"
              >{{ item }}</span
            >
          </div>
        </div>
        <p class="contitle">{{ contentData.title }}</p>
        <hr class="hr" />
        <div v-html="contentData.content" class="matter"></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      contentData: null,
      w: 0,
    };
  },
  created() {
    this.show();
    this.axios
      .get("https://apis.netstart.cn/xpc/e_article/" + this.$route.query.id)
      .then((res) => {
        this.contentData = res.data;
        this.ending();
        this.ended();
      });
  },
  methods: {
    show() {
      let timer = setInterval(() => {
        if (this.w < 70) {
          this.w = this.w + 1;
        } else {
          clearInterval("timer");
        }
      }, 20);
    },
    ending() {
      let timer = setInterval(() => {
        if (this.w < 100) {
          this.w = this.w + 1;
        } else {
          clearInterval("timer");
        }
      }, 20);
    },
    async ended() {
      await this.ending();
      setTimeout(() => {
        //active给样式display:none
        this.$refs.bar.classList.add("active");
      }, 500);
    },
  },
};
</script>

<style lang="less" scoped>
.bar {
  height: 2px;
  background-color: #c00;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 999;
  &.active {
    display: none;
  }
}
.content {
  background-color: #fff;
  padding: 30px 15px;
  .matter {
    a {
      color: brown !important;
    }
  }
  .info {
    display: flex;
    font-size: 14px;
    align-items: center;
    .label {
      display: flex;
      align-items: center;
      padding: 0 5px;
      background-color: #fdecec;
      color: #df918b;
      margin-right: 15px;
    }
    .time {
      color: #b5b5b5;
      margin-right: 15px;
    }
    .map {
      display: flex;
      span {
        color: #b5b5b5;
        display: flex;
        align-items: center;
        &::after {
          content: "·";
          font-size: 20px;
          margin: 0 2px;
        }
        &:last-child {
          &::after {
            content: "";
          }
        }
      }
    }
  }
  .contitle {
    font-size: 24px;
    font-weight: 600;
    margin: 20px 0;
  }
  .hr {
    width: 100%;
    height: 1px;
    border: none;
    background-color: #f0f0f0;
    margin-top: 40px;
    margin-bottom: 30px;
  }
}
</style>